package com.bianguo.android.apushdemo.presenter.impl;

import com.bianguo.android.apushdemo.model.impl.LocationModel;
import com.bianguo.android.apushdemo.utils.MyLog;

import java.io.IOException;

import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * Created by Administrator on 2017/9/12.
 */

public class LocationPresenter {

    private LocationModel locationModel;

    public LocationPresenter() {
        locationModel = new LocationModel();
    }

    public void location(String address, String output, String key) {
        locationModel.location(address, output, key, new Subscriber<ResponseBody>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                MyLog.mLog("location error : " + e.getMessage());
            }

            @Override
            public void onNext(ResponseBody responseBody) {
                try {
                    String location = responseBody.string();
                    MyLog.mLog("locations = " + location);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void location(String url) {
        locationModel.location(url, new Subscriber<ResponseBody>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                MyLog.mLog("location error : " + e.getMessage());
            }

            @Override
            public void onNext(ResponseBody responseBody) {
                try {
                    String location = responseBody.string();
                    MyLog.mLog("locations = " + location);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
